/**
 * 
 */
package com.wodsy.phoenix.apps.cms.homepage.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.model.IdxShopRecommended;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageShopRecService;

/**
 * @author bryan
 *
 */
@RequestMapping("/cmsShop")
@Controller
public class CmsHomePageIndexShopRecController {
	private Logger logger = LoggerFactory.getLogger(CmsHomePageIndexShopRecController.class);
	@Autowired
	private CmsHomePageShopRecService cmsHomePageShopRecService;

	/**
     * 导向首页面
     *
     * @param request 请求
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(HttpServletRequest request) {
        return "/shops";
    }
    
    /**
	 * 增加一条banner
	 */
    @RequestMapping(value = "/addOneShop", method = RequestMethod.POST)
    @ResponseBody
	public void addOneShop(IdxShopRecommended shop){
		shop.setCreateTime(new Date());
		cmsHomePageShopRecService.save(shop);
		
		
	}
	/**
	 * 获取一条banner信息
	 */
    @RequestMapping(value = "/getOneShopRecommended/{shopId}", method = RequestMethod.GET)
    @ResponseBody
	public IdxShopRecommended getOneShopRecommended(@PathVariable Integer shopId){
		IdxShopRecommended shop = cmsHomePageShopRecService.get(shopId);

		return shop;
	}
	/**
	 * 修改一条banner信息
	 */
    @RequestMapping(value = "/updateOneShopRecommended", method = RequestMethod.POST)
    @ResponseBody
    public void updateOneShopRecommended(IdxShopRecommended tbIdx){
    	tbIdx.setUpdateTime(new Date());
		
		cmsHomePageShopRecService.updateNewShopRecommended(tbIdx);
		//.update(tbIdx);
	}
	/**
	 * 根据搜索条件查询bannerList
	 */
    @RequestMapping(value = "/getAllShopRecommendedByOrder", method = RequestMethod.POST)
	@ResponseBody
    public Pager<IdxShopRecommended> getAllShopRecommendedByOrder(int pageSize,int pageNo,IdxShopRecommended shopreq){
    	//TODO
		Pager<IdxShopRecommended> adPic = new Pager<>();
		adPic.setPageSize(pageSize);
		adPic.setPageNo(pageNo);
		
		Pager<IdxShopRecommended> picPager = cmsHomePageShopRecService.searchShopRecommendedRecByOrder(adPic, shopreq);
		return picPager;
	}
	/**
	 * 更新pic状态
	 */
    @RequestMapping(value = "/updatePicShopRecommendedStatus", method = RequestMethod.POST)
    @ResponseBody
    public void updatePicShopRecommendedStatus(Integer shopId,Integer status){
    	
		cmsHomePageShopRecService.updateShopRecommendedStatus(shopId, status);
	}
	/**
	 * 更新picList状态
	 */
    @RequestMapping(value = "/updatePicShopRecommendedStatusList", method = RequestMethod.POST)
    @ResponseBody
    public void updatePicShopRecommendedStatusList(Integer[] shopIds,Integer status){
    	cmsHomePageShopRecService.updateShopRecommendedStatus(shopIds, status);
	}
    
}
